{% extends 'base.html' %}
{% load mytags %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/base.js"></script>
    <script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.css"></script>
{% endblock %}
{% block content %}

    <script>
        window.onload=init;
        function init() {
            var box = document.getElementById("appconf");
            box.className="active";
            var box = document.getElementById("project_list");
            box.className="active";
        }
    </script>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
        <form action="" method="post" id="project_form">
                {% csrf_token %}
            <div class="box">
                <div class="box-header">
                    <div class="col-sm-2" style="padding-left: 0">
						 <a href="{% url 'project_add' %}"><li class="btn btn-success" ><b>添加项目</b></li></a>
                         <a href="#" onclick="return project_export_excel()"><li name="export" class="btn btn-success search-btn-excel"><b>&nbsp;导出&nbsp;</b></li></a>
                    </div>
                    <div id="export"></div>
                </div>

                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="projectform">
                      <thead>
                        <tr>
                            <th>
                                <input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('project_form')">
                            </th>
                            <th>项目名称</th>
                            <th>程序类型</th>
                            <th>所属产品线</th>
                            <th>负责人姓名</th>
                            <th>负责人电话</th>
                            <th>操作</th>
                        </tr>
                      </thead>
                            <tbody>
                            {% for project in all_project %}
                                <tr class="even gradeX">
                                    <td><input type="checkbox" id="id" class="i-checks" value="{{ project.id }}" name="id" /></td>
                                    <td>{{ project.name }} </td>
                                    <td>{{ project.language_type }} </td>
                                    <td>{{ project.product }} </td>
                                    <td>{{ project.owner.name }} </td>
                                    <td>{{ project.owner.phone }} </td>
                                    <td>
                                        <a href="{% url "project_edit" project.id %}"><span class="btn btn-sm btn-info">编辑</span></a>
                                        <a href="{% url "project_del"%}?project_id={{ project.id }}" onclick="return confirm('确认删除项目吗？')"><span class="btn btn-sm btn-danger ">删除</span></a>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                  </table>
                  <div class="btn-group">
                      <input type="button" id="project_del" class="btn btn-danger"   name="del_button" value="删除项目"/>
                  </div>
                </div>
            </div>
        </form>
    </section>

</div>
<script>
  $(function () {
    $('#projectform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true
    });
  });
</script>
<script>

    function project_export_excel(){
        var project_id_all = getIDall();
        if (project_id_all == ''){
            if(confirm('您没有勾选，是否导出全部信息？')){
                var args = $("#project_form").serialize();
                window.location = "{% url 'project_export' %}?export=all&" + args
            }else{
                return false;
            }
        }else{
            var args = $("#project_form").serialize();
            window.location = "{% url 'project_export' %}?export=part&" + args
        }
    }

</script>
<script>
    $('#project_del').click(function () {
        var project_id_all = getIDall();
        if (project_id_all == ''){
            alert("请至少选择一行!");
            return false;
        }
        if (confirm("确定删除?")) {
            $.ajax({
                type: "post",
                data: {project_id_all: project_id_all,csrfmiddlewaretoken: '{{ csrf_token }}'},
                url: "{% url 'project_del' %}",
                success: function () {
                    parent.location.reload();
                }
            });
        }
    });
</script>
{% endblock %}
